# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=pyopenssl
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-${_realname}" "${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=18.0.0
pkgrel=1
pkgdesc="Python wrapper module around the OpenSSL library (mingw-w64)"
url='https://pypi.python.org/pypi/pyOpenSSL'
license=('LGPL2.1')
arch=('any')
makedepends=("${MINGW_PACKAGE_PREFIX}-openssl"
             "${MINGW_PACKAGE_PREFIX}-python2-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python3-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python2-cryptography"
             "${MINGW_PACKAGE_PREFIX}-python3-cryptography")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python2-pytest-runner"
              "${MINGW_PACKAGE_PREFIX}-python3-pytest-runner")
source=("https://pypi.io/packages/source/p/pyOpenSSL/pyOpenSSL-${pkgver}.tar.gz")
sha256sums=('6488f1423b00f73b7ad5167885312bb0ce410d3312eb212393795b53c8caa580')

prepare() {
  cd ${srcdir}
  cp -r pyOpenSSL-${pkgver} python2-build-${CARCH}
  cp -r pyOpenSSL-${pkgver} python3-build-${CARCH}
}

build() {
  cd "${srcdir}"
  for pver in {2,3}; do  
    msg "Python ${pver} build for ${CARCH}"  
    cd "${srcdir}/python${pver}-build-${CARCH}"
    ${MINGW_PREFIX}/bin/python${pver} setup.py build
  done
}

package_python3-pyopenssl() {
  depends=("${MINGW_PACKAGE_PREFIX}-openssl"
           "${MINGW_PACKAGE_PREFIX}-python3-cryptography"
           "${MINGW_PACKAGE_PREFIX}-python3-six")
  cd ${srcdir}/python3-build-${CARCH}
  ${MINGW_PREFIX}/bin/python3 setup.py build
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python3 setup.py install --prefix=${MINGW_PREFIX} --root="${pkgdir}" --optimize=1

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/python3-${_realname}/LICENSE"
}

package_python2-pyopenssl() {
  depends=("${MINGW_PACKAGE_PREFIX}-openssl"
           "${MINGW_PACKAGE_PREFIX}-python2-cryptography"
           "${MINGW_PACKAGE_PREFIX}-python2-six")
  cd ${srcdir}/python2-build-${CARCH}
  ${MINGW_PREFIX}/bin/python2 setup.py build
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python2 setup.py install --prefix=${MINGW_PREFIX} --root="${pkgdir}" --optimize=1

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/python2-${_realname}/LICENSE"
}

package_mingw-w64-i686-python2-pyopenssl() {
  package_python2-pyopenssl
}

package_mingw-w64-i686-python3-pyopenssl() {
  package_python3-pyopenssl
}

package_mingw-w64-x86_64-python2-pyopenssl() {
  package_python2-pyopenssl
}

package_mingw-w64-x86_64-python3-pyopenssl() {
  package_python3-pyopenssl
}
